﻿using System.Windows.Forms;
using System;

namespace CamPlug.SkypeConference.Plugin
{
	public partial class PropertiesForm : Form
	{
		SkypeConferencePlugin Plugin;

		public PropertiesForm(SkypeConferencePlugin plugin)
		{
			this.Plugin = plugin;
			InitializeComponent();
		}

		void TimerUpdateUI_Tick(object sender, System.EventArgs e)
		{
			LabelCurrentWaitingDurationValue.Text = Plugin.CallMonitor.CurrentWaitingToTalkDuration.ToString("mm\\:ss");
			LabelCurrentTalkingDurationValue.Text = Plugin.CallMonitor.CurrentTalkingDuration.ToString("mm\\:ss");
			LabelTotalTalkingDurationValue.Text = Plugin.CallMonitor.TotalTalkingDuration.ToString("hh\\:mm\\:ss");
			LabelTotalWaitingDurationValue.Text = Plugin.CallMonitor.TotalWaitingToTalkDuration.ToString("hh\\:mm\\:ss");
			GroupBoxCallStatus.Enabled = (
					Plugin.CallMonitor.Status != CallMonitorStatus.AttachedButNotInCall
					&& Plugin.CallMonitor.Status != CallMonitorStatus.NotAttached);
			CheckBoxWaitingToTalk.Checked = Plugin.CallMonitor.Status == CallMonitorStatus.WaitingToTalk;
			CheckBoxTalking.Checked = Plugin.CallMonitor.Status == CallMonitorStatus.Talking;
		}

		void PropertiesForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			e.Cancel = true;
			Hide();
		}

		void PropertiesForm_Shown(object sender, EventArgs e)
		{
			Location = Cursor.Position;
		}

		void PropertiesForm_VisibleChanged(object sender, EventArgs e)
		{
			TimerUpdateUI.Enabled = Visible;		
		}

		void CheckBoxWaitingToTalk_Click(object sender, EventArgs e)
		{
			if (CheckBoxWaitingToTalk.Checked)
				Plugin.CallMonitor.Status = CallMonitorStatus.WaitingToTalk;
			else
				Plugin.CallMonitor.Status = CallMonitorStatus.Listening;
		}

		void CheckBoxTalking_Click(object sender, EventArgs e)
		{
			if (CheckBoxTalking.Checked)
				Plugin.CallMonitor.Status = CallMonitorStatus.Talking;
			else
				Plugin.CallMonitor.Status = CallMonitorStatus.Listening;
		}

		void ButtonResetStatistics_Click(object sender, EventArgs e)
		{
			Plugin.CallMonitor.ResetStatistics();
		}

	}
}
